import { reqCurDate } from './../service/business/goods/index'
/*
 * @Author: 'Chenfarry' '2925102113@qq.com'
 * @Date: 2024-07-22 17:55:50
 * @LastEditors: chenhuanhuan 2925102113@qq.com
 * @LastEditTime: 2024-09-19 14:21:40
 * @FilePath: \orderApp\utils\time.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
dayjs.locale('zh-cn')

export const getWeekDate = (flag = 'current', type = 'YYYY-MM-DD') => {
  let date = ref<any>('')
  switch (flag) {
    case 'last':
      date.value = dayjs().add(-1, 'week')
      break
    case 'current':
      date.value = dayjs().add(0, 'week')
      break
    case 'next':
      date.value = dayjs().add(1, 'week')
      break
  }

  const startOfWeek = date.value.startOf('week')
  const endOfWeek = date.value.endOf('week')

  // 创建一个数组存储周一到周日的所有日期
  const dates = []
  let currentDate = startOfWeek

  while (currentDate.isBefore(endOfWeek) || currentDate.isSame(endOfWeek, 'day')) {
    dates.push(currentDate.format(type))
    currentDate = currentDate.add(1, 'day')
  }

  return dates

}

/**
 * 
 * @param start 一周的任意一天
 * @param type 时间格式化
 */
export const getAnyWeek =(start,type='YYYY-MM-DD')=>{
  const startOfWeek = start.startOf('week')
  const endOfWeek = start.endOf('week')

  // 创建一个数组存储周一到周日的所有日期
  const dates = []
  let currentDate = startOfWeek

  while (currentDate.isBefore(endOfWeek) || currentDate.isSame(endOfWeek, 'day')) {
    dates.push(currentDate.format(type))
    currentDate = currentDate.add(1, 'day')
  }
  return dates
}
